# -*- coding:utf-8 -*-

from tornado.web import HTTPError,authenticated
from libs.handler import BaseHandler

class Basic(BaseHandler):
    @authenticated
    def get(self):
        self.render("accounts/basic.html")
    
    @authenticated
    def post(self):
        nick_name = self.get_argument("nick_name",None)
        gender    = self.get_argument("gender", 0)
        cannotfind = self.get_argument("cannotfind", 0)
        
        user = self.get_current_user()
        self.db.execute("UPDATE users SET nick_name = %s,gender=%s,cannotfind=%s WHERE id=%s", nick_name, gender, cannotfind, user["id"])
        
        domain = self.get_argument("domain", None)
        if None != domain and ''== user["domain"]:
            self.db.execute("UPDATE users SET domain=%s WHERE id=%s", domain, user["id"])
        
        self.redirect("/accounts/basic")

class EditPassword(BaseHandler):
    @authenticated
    def get(self):
        self.render("accounts/editpassword.html")
    
    @authenticated
    def post(self):
        self.redirect("/accounts/editpassword")

class EmailChange(BaseHandler):
    def get(self):
        self.render("accounts/emailchange.html");
        
    def post(self):
        new_email = self.get_argument("new_email", None)
        
    
handlers = []
handlers = [
    (r"/accounts/basic",Basic),
    (r"/accounts/emailchange",EmailChange),
    (r"/accounts/editpassword",EditPassword)
]
